package com.nulldev.util.uri.http;

import java.nio.charset.Charset;

import com.nulldev.util.math.MathUtil;

public final class HTTP
{
    public static final int CR = 13;
    public static final int LF = 10;
    public static final int SP = 32;
    public static final int HT = 9;
    public static final String TRANSFER_ENCODING = "Transfer-Encoding";
    public static final String CONTENT_LEN = "Content-Length";
    public static final String CONTENT_TYPE = "Content-Type";
    public static final String CONTENT_ENCODING = "Content-Encoding";
    public static final String EXPECT_DIRECTIVE = "Expect";
    public static final String CONN_DIRECTIVE = "Connection";
    public static final String TARGET_HOST = "Host";
    public static final String USER_AGENT = "User-Agent";
    public static final String DATE_HEADER = "Date";
    public static final String SERVER_HEADER = "Server";
    public static final String EXPECT_CONTINUE = "100-continue";
    public static final String CONN_CLOSE = "Close";
    public static final String CONN_KEEP_ALIVE = "Keep-Alive";
    public static final String CHUNK_CODING = "chunked";
    public static final String IDENTITY_CODING = "identity";
    public static final Charset DEF_CONTENT_CHARSET;
    public static final Charset DEF_PROTOCOL_CHARSET;
    @Deprecated
    public static final String UTF_8 = "UTF-8";
    @Deprecated
    public static final String UTF_16 = "UTF-16";
    @Deprecated
    public static final String US_ASCII = "US-ASCII";
    @Deprecated
    public static final String ASCII = "ASCII";
    @Deprecated
    public static final String ISO_8859_1 = "ISO-8859-1";
    @Deprecated
    public static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
    @Deprecated
    public static final String DEFAULT_PROTOCOL_CHARSET = "US-ASCII";
    @Deprecated
    public static final String OCTET_STREAM_TYPE = "application/octet-stream";
    @Deprecated
    public static final String PLAIN_TEXT_TYPE = "text/plain";
    @Deprecated
    public static final String CHARSET_PARAM = "; charset=";
    @Deprecated
    public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
    
    /**
     * HTTP Codes
     */
    
	public static final int OK = 200;
	public static final int NOT_FOUND = 404;
	public static final int PERMISSON_DENIED = 403;
	public static final int BAD_REQUEST = 400;
	public static final int INT_ERROR = 500;
	public static final int TOO_LARGE_DATA = 413;
	public static final int UNAUTH = 401;
	public static final int ACCEPT = 202;
	public static final int TIMEOUT = 408;
	/**
	 * | <br>
	 * |><br>
	 * | <br>
	 * |X<br>
	 * | <br>
	 */
	public static final int REFUSED_LEGALLY = 521;
	
	/**
	 * Custom HTTP Codes <br>
	 * <b> UNSUPPORTED_WEBKIT </b> | Used by iWebKit if using an outdated build.
	 */
	
	public static final int UNSUPPORTED_WEBKIT = 601;
	
	/**
	 * Satirical HTTP Code
	 */
	public static final int TEAPOT = 418;
	
	
	public static final String POST_REQUEST = "POST";
	public static final String GET_REQUEST = "GET";

    public static boolean isWhitespace(final char ch) {
        return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
    }

    static {
        DEF_CONTENT_CHARSET = Charset.forName("ISO-8859-1");
        DEF_PROTOCOL_CHARSET = Charset.forName("US-ASCII");
    }

	public static boolean isOK(final int responseCode) {
		return MathUtil.between(responseCode, 100, 200) || responseCode == 200 || responseCode == 302;
	}
}
